/* The following code will add a movie to a customer's list of current rentals (i.e.
they will rent the movie). The code first checks to be sure that it has all of
the necessary information to process the request, i.e. the videoID and the customerID.
If the necessary information is present, a cursor is established on the "RENTALS" table and a row is added to indicate the new rental. Otherwise, the user is redirected to another
page where more information may be gathered, or if they reached this page in error.
*/
if(request.videoID != null)
{
client.videoID = request.videoID;
}
if(request.customerID != null)
{
client.customerID = request.customerID;
}
if(client.videoID != null && client.customerID != null)
{
/* if both the videoID and customerID are known
create a new record in the rentals database for this
customer and add their rental info.
*/
var userId = unscramble(client.userId)
var bucket = project.sharedConnections.connections[userId]
var connection = bucket.connection
cursor = connection.cursor("select * from rentals", true);
cursor.next();
cursor.customerid = client.customerID;
cursor.videoid = client.videoID;
cursor.invoicenum = 42;
today = new Date();
cursor.rentaldate = today;
duedate = new Date();
duedate.setDate(today.getDate() + 3);
duedate.setHours(23);
duedate.setMinutes(0);
duedate.setSeconds(0);
cursor.duedate = duedate;
cursor.returndate = null;
cursor.insertRow("rentals");
cursor.close();
redirect("status.htm");
}
else if(client.customerID == null)
{
// send them back to sign in
redirect("client.htm");
}
else if(client.videoID == null)
{
redirect("status.htm");
}
else
{
redirect("pick.htm");
}